/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.whu.weibo_souhu.login;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Administrator
 */
public class MD5 {  
    public  String getMD5(String inStr) throws NoSuchAlgorithmException
    {
        MessageDigest md5=null;
        md5=MessageDigest.getInstance("MD5");
        
        char[] mychar=inStr.toCharArray();
        byte[] mybyte=new byte[mychar.length];
        int i;
        for(i=0;i<mychar.length;i++)
            mybyte[i]=(byte) mychar[i];
        
        byte[] md5byte=md5.digest(mybyte);
        StringBuffer hexValue=new StringBuffer();
        for(i=0;i<md5byte.length;i++)
        {
               int val = ((int) md5byte[i]) & 0xff;
               if (val < 16)
                   hexValue.append("0");
               hexValue.append(Integer.toHexString(val));
        }
        return hexValue.toString();
    }
  public static void main(String args[]) {
  String s = new String("ximo128504");

  MD5 md5=new MD5();
        try {
            System.out.println("MD5后：" + md5.getMD5(s));
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MD5.class.getName()).log(Level.SEVERE, null, ex);
        }
          System.out.println("原始：" + s);
 }
   
}
